feat(demo): HyDE Theater — hypothetical document embeddings, before/after - #10
Merged
Merged
Conversation
…fter Adds a sixth flagship surface (/hyde) showcasing HyDE — embedding a hypothetical *answer* (document-space) instead of the raw query (query-space) to close the distribution gap. - demo/hyde.py — HyDEEngine runs the real comparison: it synthesizes a document-shaped hypothesis with a deterministic, generic template (labelled rule-based / no-LLM, following konjoai.retrieve.hyde's real _HYDE_PROMPT intent), then runs the *same* real dense cosine retrieval on both the raw query and the hypothesis. Before/after rankings, per-doc score deltas, and the closed top-document gap are measured, not staged. - demo/pipeline.py — public dense() (real cosine retrieval as formatted rows), reused for both baseline and HyDE runs. - demo/hyde.html — cinematic "close the gap" view: query vs hypothesis with embedding stats, a typewriter hypothesis reveal, an animated top-similarity gap meter (query → HyDE delta), and side-by-side retrieval columns with per-document rank/score deltas. Ships reduced-motion, focus-visible, view-transition and responsive layout. - demo/server.py — GET /hyde + GET /api/hyde/analyze (bounded inputs). - HyDE linked in the nav across all surfaces (now: Playground · Observatory · Pipeline · Agent · Security · HyDE). - tests/unit/test_demo_hyde.py — 7 contract tests (shape + no-LLM label, hypothesis denser than query, real bounded ranked retrieval, delta arithmetic, winner is a real source). 43 demo tests pass (stable across PYTHONHASHSEED); ruff clean repo-wide. https://claude.ai/code/session_01WWWgV1NwxaaNdPfy4PHN1K
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A sixth flagship demo surface (
/hyde) showcasing HyDE (Hypothetical Document Embeddings, Gao et al. 2022): embed a hypothetical answer (document-space) instead of the raw query (query-space) to close the distribution gap.What's new
demo/hyde.py—HyDEEngineruns the real before/after comparison. It synthesizes a document-shaped hypothesis with a deterministic, generic template (labelledrule-based/ no-LLM, followingkonjoai.retrieve.hyde's real_HYDE_PROMPTintent), then runs the same real dense cosine retrieval on both the raw query and the hypothesis. Before/after rankings, per-document score deltas, and the closed top-document gap are measured, not staged.demo/pipeline.py— publicdense()(real cosine retrieval as formatted rows), reused for both runs.demo/hyde.html— cinematic "close the gap" view: query vs hypothesis with embedding stats (tokens / non-zero dims), a typewriter hypothesis reveal, an animated top-similarity gap meter (query → HyDE delta), and side-by-side retrieval columns with per-document rank/score deltas. Ships reduced-motion, focus-visible, View Transitions, and responsive layout.demo/server.py—GET /hyde+GET /api/hyde/analyze(bounded inputs).tests/unit/test_demo_hyde.py— 7 contract tests (shape + no-LLM label, hypothesis denser than query, real bounded ranked retrieval, delta arithmetic, winner is a real source).The effect (real numbers)
For "What are my GDPR rights?" the top-document cosine rises 0.18 → 0.51 (+0.33) — the query→document gap closing, because the hypothesis paragraph lands in document-space.
Honesty notes
hypothesis_sourceand on the page). The embeddings, cosine scores, and rankings are realkonjoaidense retrieval.Verification
PYTHONHASHSEEDvalues;ruff check .clean repo-wide.200; the HyDE endpoint returns the measured delta.demo/*+ a new test changed — no productionkonjoai/code touched.Run it:
python3 demo/server.py # http://localhost:8766/hydehttps://claude.ai/code/session_01WWWgV1NwxaaNdPfy4PHN1K
Generated by Claude Code